﻿using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using WebProject.Core.Models;

namespace WebProject.Models
{
    public class ProductionModel
    {
        public ProductionModel()
        {
            
        }

        public ProductionModel(Production production)
        {
            Id = production.Id;
            ProductionName = production.ProductionName;
            ProductionType = production.ProductionType;
            ProductionImageUrl = production.ProductionImageUrl;
            CreateDate = production.CreateDate;
            IsDisplay = production.IsDisplay;
            IsDisplayOnIndex = production.IsDisplayOnIndex;
            Summary = production.Summary;
            Description = production.Description;
        }

        public int Id
        {
            get; set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [StringLength(40, ErrorMessage = "{0}的最大长度为{1}个字符。")]
        [DisplayName("产品名")]
        public string ProductionName
        {
            get; set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [StringLength(20, ErrorMessage = "{0}的最大长度为{1}个字符。")]
        [DisplayName("产品分类")]
        public ProductionType ProductionType
        {
            get; set;
        }

        [DisplayName("产品插图路径")]
        public string ProductionImageUrl
        {
            get; set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [DisplayName("产品发布日期")]
        public DateTime CreateDate
        {
            get; set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [DisplayName("是否显示")]
        public bool IsDisplay
        {
            get; set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [DisplayName("是否在首页显示")]
        public bool IsDisplayOnIndex
        {
            get;
            set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [DisplayName("产品概要描述")]
        [StringLength(200, ErrorMessage = "{0}的最大长度为{1}个字符。")]
        public string Summary
        {
            get; set;
        }

        [Required(ErrorMessage = "{0}为必填项")]
        [DisplayName("产品详细描述")]
        [StringLength(1000, ErrorMessage = "{0}的最大长度为{1}个字符。")]
        public string Description
        {
            get;
            set;
        }

        public Production ToProduction()
        {
            return new Production
                {
                    CreateDate = CreateDate,
                    Description = Description,
                    Id = Id,
                    IsDisplay = IsDisplay,
                    IsDisplayOnIndex = IsDisplayOnIndex,
                    ProductionImageUrl = ProductionImageUrl,
                    ProductionName = ProductionName,
                    ProductionType = ProductionType,
                    Summary = Summary,
                };
        }
    }
}